package com.whfc.fim.redis.impl;

import com.alibaba.fastjson.JSONObject;
import com.whfc.fim.dto.WarnCacheDTO;
import com.whfc.fim.redis.FimWarnRecordRedisDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;


/**
 * @author sun_guodong
 * @description
 * @date 2019-12-06
 */
@Repository
public class FImWarnRecordRedisDaoImpl implements FimWarnRecordRedisDao {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void setWarnRecord(String key, WarnCacheDTO value) {
        redisTemplate.opsForValue().set(key, JSONObject.toJSONString(value), 1, TimeUnit.DAYS);
    }

    @Override
    public WarnCacheDTO getWarnRecord(String key) {
        String s = redisTemplate.opsForValue().get(key);
        if (!StringUtils.isBlank(s)) {
            return JSONObject.parseObject(s, WarnCacheDTO.class);
        }
        return null;
    }

    @Override
    public void delWarnRecord(String key) {
        redisTemplate.delete(key);
    }
}

